﻿<UserControl x:Class="WinMilk.Gui.Controls.IconButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
    
    <Grid x:Name="LayoutRoot">
        <Button Name="Button" BorderBrush="{x:Null}" Click="Button_Click">
        	<Button.Resources>
        		<Style x:Key="ButtonStyle" TargetType="Button">
        			<Setter Property="Background" Value="Transparent"/>
        			<Setter Property="BorderBrush" Value="Transparent"/>
        			<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        			<Setter Property="BorderThickness" Value="0"/>
        			<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
        			<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        			<Setter Property="Padding" Value="0"/>
        			<Setter Property="Template">
        				<Setter.Value>
        					<ControlTemplate TargetType="Button">
        						<Grid Background="Transparent">
        							<VisualStateManager.VisualStateGroups>
        								<VisualStateGroup x:Name="CommonStates">
        									<VisualState x:Name="Normal"/>
        									<VisualState x:Name="MouseOver"/>
        									<VisualState x:Name="Pressed">
        										<Storyboard>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
        												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
        											</ObjectAnimationUsingKeyFrames>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
        											</ObjectAnimationUsingKeyFrames>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
        											</ObjectAnimationUsingKeyFrames>
        										</Storyboard>
        									</VisualState>
        									<VisualState x:Name="Disabled">
        										<Storyboard>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
        												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
        											</ObjectAnimationUsingKeyFrames>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
        												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
        											</ObjectAnimationUsingKeyFrames>
        											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
        												<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
        											</ObjectAnimationUsingKeyFrames>
        										</Storyboard>
        									</VisualState>
        								</VisualStateGroup>
        							</VisualStateManager.VisualStateGroups>
                                    <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
        								<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
        							</Border>
        						</Grid>
        					</ControlTemplate>
        				</Setter.Value>
        			</Setter>
        		</Style>
        	</Button.Resources>
			
        	<Button.Style>
        		<StaticResource ResourceKey="ButtonStyle"/>
        	</Button.Style>
            
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                
                <Grid Grid.Column="0" Visibility="{StaticResource PhoneDarkThemeVisibility}">
                    <Image Source="{Binding IconSource}" Width="32" />
                    <Image Source="/icons/appbar.basecircle.rest.png" Width="32" />
                </Grid>

                <Grid Grid.Column="0" Visibility="{StaticResource PhoneLightThemeVisibility}">
                    <Image Source="{Binding LightIconSource}" Width="32" />
                    <Image Source="/icons/light/appbar.basecircle.rest.png" Width="32" />
                </Grid>

                <TextBlock Name="TextBlock" Text="{Binding Text}" VerticalAlignment="Center" Grid.Column="2" />
            </Grid>
            
        </Button>
    </Grid>
</UserControl>
